<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set the leniency of the parser</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="intldateformatter.setcalendar.html">« IntlDateFormatter::setCalendar</a></li>
      <li style="float: right;"><a href="intldateformatter.setpattern.html">IntlDateFormatter::setPattern »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.intldateformatter.html">IntlDateFormatter</a></li>
    <li>Set the leniency of the parser</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="intldateformatter.setlenient" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">IntlDateFormatter::setLenient</h1>
  <h1 class="refname">datefmt_set_lenient</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">IntlDateFormatter::setLenient</span> -- <span class="refname">datefmt_set_lenient</span> &mdash; <span class="dc-title">Set the leniency of the parser</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-intldateformatter.setlenient-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
   <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>IntlDateFormatter::setLenient</strong></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$lenient</code></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>datefmt_set_lenient</strong></span>(<span class="methodparam"><span class="type"><a href="class.intldateformatter.html" class="type IntlDateFormatter">IntlDateFormatter</a></span> <code class="parameter">$formatter</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$lenient</code></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
  Define if the parser is strict or lenient in interpreting inputs that do not match the pattern exactly.
  Enabling lenient parsing allows the parser to accept otherwise flawed date or 
  time patterns, parsing as much as possible to obtain a value.
  Extra space, unrecognized tokens, or invalid values (&quot;February 30th&quot;) are not accepted.  
  </p> 
  </div>


 <div class="refsect1 parameters" id="refsect1-intldateformatter.setlenient-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">formatter</code></dt>

     <dd>

      <p class="para">
       The formatter resource      
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">lenient</code></dt>

     <dd>

      <p class="para">
       Sets whether the parser is lenient or not, default is <strong><code>true</code></strong> (lenient).
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

   
 
 <div class="refsect1 returnvalues" id="refsect1-intldateformatter.setlenient-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-intldateformatter.setlenient-examples">
  <h3 class="title">范例</h3>
   <div class="example" id="example-2453">
    <p><strong>示例 #1 <span class="function"><strong>datefmt_set_lenient()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">datefmt_create</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'America/Los_Angeles'</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">GREGORIAN</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'dd/MM/yyyy'<br /></span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">'lenient&nbsp;of&nbsp;the&nbsp;formatter&nbsp;is&nbsp;:&nbsp;'</span><span style="color: #007700">;<br />if&nbsp;(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isLenient</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'TRUE'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'FALSE'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">datefmt_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'35/13/1971'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"\n&nbsp;Trying&nbsp;to&nbsp;do&nbsp;parse('35/13/1971').\nResult&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">datefmt_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'35/13/1971'</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">intl_get_error_code</span><span style="color: #007700">()&nbsp;!=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nError_msg&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">intl_get_error_message</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nError_code&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">intl_get_error_code</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">datefmt_set_lenient</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"\nNow&nbsp;lenient&nbsp;of&nbsp;the&nbsp;formatter&nbsp;is&nbsp;:&nbsp;"</span><span style="color: #007700">;<br />if&nbsp;(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isLenient</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'TRUE'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'FALSE'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">datefmt_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'35/13/1971'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"\nTrying&nbsp;to&nbsp;do&nbsp;parse('35/13/1971').\nResult&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">datefmt_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'35/13/1971'</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">intl_get_error_code</span><span style="color: #007700">()&nbsp;!=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nError_msg&nbsp;is&nbsp;:&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">intl_get_error_message</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nError_code&nbsp;is&nbsp;:&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">intl_get_error_code</span><span style="color: #007700">();<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-2454">
    <p><strong>示例 #2 OO example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'America/Los_Angeles'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">GREGORIAN</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'dd/MM/yyyy'<br /></span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">'lenient&nbsp;of&nbsp;the&nbsp;formatter&nbsp;is&nbsp;:&nbsp;'</span><span style="color: #007700">;<br />if&nbsp;(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isLenient</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'TRUE'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'FALSE'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">parse</span><span style="color: #007700">(</span><span style="color: #DD0000">'35/13/1971'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"\n&nbsp;Trying&nbsp;to&nbsp;do&nbsp;parse('35/13/1971').\nResult&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">parse</span><span style="color: #007700">(</span><span style="color: #DD0000">'35/13/1971'</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">intl_get_error_code</span><span style="color: #007700">()&nbsp;!=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nError_msg&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">intl_get_error_message</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nError_code&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">intl_get_error_code</span><span style="color: #007700">();<br />}<br /><br /></span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setLenient</span><span style="color: #007700">(</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"\nNow&nbsp;lenient&nbsp;of&nbsp;the&nbsp;formatter&nbsp;is&nbsp;:&nbsp;"</span><span style="color: #007700">;<br />if&nbsp;(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isLenient</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'TRUE'</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'FALSE'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">parse</span><span style="color: #007700">(</span><span style="color: #DD0000">'35/13/1971'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"\n&nbsp;Trying&nbsp;to&nbsp;do&nbsp;parse('35/13/1971').\nResult&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">parse</span><span style="color: #007700">(</span><span style="color: #DD0000">'35/13/1971'</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">intl_get_error_code</span><span style="color: #007700">()&nbsp;!=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nError_msg&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">intl_get_error_message</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\nError_code&nbsp;is&nbsp;:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">intl_get_error_code</span><span style="color: #007700">();<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
     <p class="para">以上例程会输出：</p>
     <div class="example-contents screen">
         <div class="cdata"><pre>
lenient of the formatter is : TRUE
Trying to do parse(&#039;35/13/1971&#039;).
Result is : 66038400
Now lenient of the formatter is : FALSE
Trying to do parse(&#039;35/13/1971&#039;).
Result is : 
Error_msg is : Date parsing failed: U_PARSE_ERROR
Error_code is : 9

</pre></div>
     </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-intldateformatter.setlenient-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
    <ul class="simplelist">
    <li class="member"><span class="function"><a href="intldateformatter.islenient.html" class="function" rel="rdfs-seeAlso">datefmt_is_lenient()</a> - Get the lenient used for the IntlDateFormatter</span></li>
    <li class="member"><span class="function"><a href="intldateformatter.create.html" class="function" rel="rdfs-seeAlso">datefmt_create()</a> - Create a date formatter</span></li>
    </ul>
  </p>
 </div>

</div></div></div></body></html>